package com.borrower.action;

import com.borrower.service.BorrowerServiceImpl;
import com.pojo.BorrowerBean;
import com.utils.EncryptUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginAction extends Action{
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();
        String userName = request.getParameter("userName");
        String borPassword = request.getParameter("borPassword");
        String pwd=null;
        try {
            pwd= EncryptUtils.desEncrypt(borPassword);
        } catch (Exception e) {
            e.printStackTrace();
        }

        BorrowerBean bor = new BorrowerBean();
        bor.setBorPwd(pwd);
        bor.setUserName(userName);

        BorrowerServiceImpl service = new BorrowerServiceImpl();
        if (service.Login(bor)){
            HttpSession session = request.getSession();
            session.setAttribute("loginName",bor.getUserName());
//            session.setAttribute("loginid",bor.getUserId());
            out.print("登录成功");
        }else {
            out.print("登录失败");
        }

    }
}
